2020-2021 Sunseeker Telemetry and Lighting System
adc10_a_ex5_battMonitor.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
66 //******************************************************************************
67 #include "driverlib.h"
68 
69 void main (void)
70 {
71  //Stop Watchdog Timer
72  WDT_A_hold(WDT_A_BASE);
73 
74  //Initialize the ADC10_A Module
75  /*
76  * Base Address for the ADC10_A Module
77  * Use internal ADC10_A bit as sample/hold signal to start conversion
78  * USE MODOSC 5MHZ Digital Oscillator as clock source
79  * Use default clock divider of 1
80  */
81  ADC10_A_init(ADC10_A_BASE,
82  ADC10_A_SAMPLEHOLDSOURCE_SC,
83  ADC10_A_CLOCKSOURCE_ADC10OSC,
84  ADC10_A_CLOCKDIVIDER_1);
85 
86  ADC10_A_enable(ADC10_A_BASE);
87 
88  /*
89  * Base Address for the ADC10_A Module
90  * Sample/hold for 16 clock cycles
91  * Do not enable Multiple Sampling
92  */
93  ADC10_A_setupSamplingTimer(ADC10_A_BASE,
94  ADC10_A_CYCLEHOLD_16_CYCLES,
95  ADC10_A_MULTIPLESAMPLESDISABLE);
96 
97  //Configure Memory Buffer
98  /*
99  * Base Address for the ADC10_A Module
100  * Use (Vcc-Vss)/2 as input
101  * Use positive reference of Internally generated Vref
102  * Use negative reference of AVss
103  */
104  ADC10_A_configureMemory(ADC10_A_BASE,
105  ADC10_A_INPUT_BATTERYMONITOR,
106  ADC10_A_VREFPOS_INT,
107  ADC10_A_VREFNEG_AVSS);
108 
109  //Configure internal reference
110  //If ref generator busy, WAIT
111  while ( REF_BUSY == Ref_isRefGenBusy(REF_BASE) ) ;
112  //Select internal ref = 1.5V
113  Ref_setReferenceVoltage(REF_BASE,
114  REF_VREF1_5V);
115  //Internal Reference ON
116  Ref_enableReferenceVoltage(REF_BASE);
117 
118  //Delay (~75us) for Ref to settle
119  __delay_cycles(75);
120 
121  //Set P1.0 to output direction
122  GPIO_setAsOutputPin(
123  GPIO_PORT_P1,
124  GPIO_PIN0
125  );
126 
127  //Clear P1.0 LED off
129  GPIO_PORT_P1,
130  GPIO_PIN0
131  );
132 
133  while (1)
134  {
135  //Enable and Start the conversion
136  //in Single-Channel, Single-Conversion Mode
137  ADC10_A_startConversion(ADC10_A_BASE,
138  ADC10_A_SINGLECHANNEL);
139  //ADC10BUSY?
140  while (ADC10_A_isBusy(ADC10_A_BASE)) ;
141 
142  //For debug only
143  __no_operation();
144 
145  //Is ADC10MEM = A11 > 1.15V?
146  if (ADC10_A_getResults(ADC10_A_BASE) < 0x311){
147  //Clear P1.0 LED off
149  GPIO_PORT_P1,
150  GPIO_PIN0
151  );
152  } else {
153  //Set P1.0 LED on
155  GPIO_PORT_P1,
156  GPIO_PIN0
157  );
158  }
159  }
160 }
161 
void main(void)
__no_operation()
GPIO_setOutputHighOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
GPIO_setOutputLowOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
__delay_cycles(500000)